const express = require('express')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const userRouter = require('./user/user')
const app = express()

// work with express
const server = require('http').Server(app)
const io = require('socket.io')(server)
io.on('connection', function(socket) {
    socket.on('sendmsg', data => {
        io.emit('recvmsg', data)
    })
})

// 引入中间件注意依赖关系
app.use(bodyParser.json())
app.use(bodyParser.urlencoded())
app.use(cookieParser())
// 在用到的中间件之后引用路由
app.use('/user', userRouter)
// 创建服务
server.listen(3030, function() {
    console.log('runing at 3030')
})

